package com.example.app.global

import android.content.Context
import com.blankj.utilcode.util.DeviceUtils
import com.example.app.manager.Themis
import com.libcommon.ext.workIO
import com.libcommon.mmkv.MKKey
import com.libcommon.mmkv.MKManager

/**
 * Created on 2022/9/15.
 * @author Joker
 * Des: app常量池 供全应用业务会用到的常量
 */

object GlobalConstant {

    /**
     * 唯一设备标识符号
     */
    val deviceTag = "${DeviceUtils.getAndroidID()}${DeviceUtils.getUniqueDeviceId()}"


    const val TYPE_BOY = 1  //男
    const val TYPE_GIRL = 2 //女


    private var phoneLevel = Themis.DEVICE_LEVEL_LOW

    //手机等级
    fun getPhoneLevel(): Int {
        return if (phoneLevel == -1) Themis.DEVICE_LEVEL_LOW else phoneLevel
    }

    //是否是低端机
    fun isLowPhone(): Boolean = getPhoneLevel() == Themis.DEVICE_LEVEL_LOW

    /**
     * 初始化获取一次机型
     */
    fun initDeviceLevel(context: Context) {
        val level = MKManager.getInt(MKKey.PHONE_LEVEL, -1)
        if (level == -1) {
            workIO {
                phoneLevel = Themis.judgeDeviceLevel(context)
                MKManager.put(MKKey.PHONE_LEVEL, phoneLevel)
            }
        } else phoneLevel = level
    }

    fun getDownloadSize() = when (getPhoneLevel()) {
        Themis.DEVICE_LEVEL_HIGH -> if (GlobalUserManager.isLogin()) 5 else 15
        Themis.DEVICE_LEVEL_MID -> if (GlobalUserManager.isLogin()) 3 else 10
        else -> if (GlobalUserManager.isLogin()) 1 else 5
    }

}